<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    protected $table = 'mckj_user';

    protected $fillable = ['name', 'email'];

    public $timestamps = false;

    public function getSexTextAttribute()
    {
        return $this->sex == 1 ? "男" : "女";
    }

    public function getAvatarAttribute()
    {
        foreach (['middle', 'big', 'small'] as $type) {
            $avatar = $this->getAttribute($type . "Avatar");
            if (substr($avatar, 0, 4) == 'http') {
                return $avatar;
            }
            if ($avatar) {
                return sprintf('http://api.abt2017.com/%s', trim($avatar));
            }
        }
        return asset('image/noavatar_middle.gif');

    }
}
